package com.ruoyi.stock2.fasttext;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class UserTestModel {

    public static void main(String[] args) {

        testmodel();
    }
    public static void testmodel(){
        int totalCount = 0;
        int correctCount = 0;
        int errorCount = 0;

        FastText fasttext = new FastText();
        try {
            fasttext.loadModel("X:\\opt\\model_type1.model.bin");
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            FileReader fr = new FileReader("X:\\opt\\model_type_test.txt");
            BufferedReader bf = new BufferedReader(fr);
            String str;
            String type = "";
            while ((str = bf.readLine()) != null) {
                totalCount = totalCount + 1;
//                String str1 = str.substring("__label__u 000001 20190816 20190827".length()+1);
//                String str2 = str.substring(0,"__label__u".length());

                String str1 = str.substring("__label__1".length()+1);
                String str2 = str.substring(0,"__label__1".length());

                String[] result = str1.split(" ");
                List<Pair<Float, String>> list = fasttext.predict(result, 1);
                for (Pair<Float, String> parir : list) {
                    type = parir.getValue();
                }
                if(type.equals(str2)){
                    correctCount = correctCount + 1;

                }else{
                    errorCount = errorCount + 1;
                    System.out.println(str);
                }

            }
            System.out.println("totalCount:" + totalCount);
            System.out.println("correctCount:" + correctCount);
            System.out.println("errorCount:" + errorCount);
            System.out.println("Accuracy% is :" + ((float) correctCount / totalCount * 100));

            bf.close();
            fr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
